home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 5 / Apprentice-Release5.iso / Source Code / C / Frameworks / TransSkel 3.24 / Demos / C Demos / Button / Modeless.c < prev    next >
Text File  |  1994-10-24  |  2KB  |  84 lines

  1. /*
  2.  * The stuff in this file presents a modeless dialog with an outlined
  3.  * pushbutton.  It demonstrates:
  4.  * - Button outlining in a modeless dialog.
  5.  *
  6.  * Note that button clicks are tracked and return/enter and escape/
  7.  * command-period keyclicks are mapped onto button clicks, but that no
  8.  * other action is associated with those clicks.  This window hander
  9.  * just shows the visible user interface stuff associated with those
  10.  * actions.
  11.  */
  12.  
  13. # include    "TransSkel.h"
  14.  
  15. # include    "Button.h"
  16.  
  17.  
  18. typedef enum
  19. {
  20.     okBtn = 1,
  21.     cancelBtn
  22. };
  23.  
  24.  
  25. static pascal Boolean
  26. Filter (DialogPtr dlog, EventRecord *evt, short *item)
  27. {
  28. Boolean    result = false;
  29. short    hilite;
  30.  
  31.     switch (evt->what)
  32.     {
  33.     case updateEvt:
  34.         SkelDrawButtonOutline (SkelGetDlogCtl (dlog, okBtn));
  35.         break;
  36.     case activateEvt:
  37.         hilite = ((evt->modifiers & activeFlag) ? normalHilite : dimHilite);
  38.         (void) SkelSetDlogCtlHilite (dlog, okBtn, hilite);
  39.         SkelDrawButtonOutline (SkelGetDlogCtl (dlog, okBtn));
  40.         (void) SkelSetDlogCtlHilite (dlog, cancelBtn, hilite);
  41.         break;
  42.     case keyDown:
  43.         result = SkelDlogMapKeyToButton (dlog, evt, item, okBtn, cancelBtn);
  44.         break;
  45.     }
  46.     return (result);
  47. }
  48.  
  49.  
  50. static pascal void
  51. Clobber (void)
  52. {
  53. DialogPtr    dlog;
  54.  
  55.     GetPort (&dlog);
  56.     HideWindow (dlog);
  57.     DisposeDialog (dlog);
  58. }
  59.  
  60.  
  61. /*
  62.  * Initialize modeless dialog
  63.  */
  64.  
  65. void
  66. SetupModeless (void)
  67. {
  68. DialogPtr    dlog;
  69.  
  70.     dlog = GetNewDialog (modelessRes, nil, (WindowPtr) -1L);
  71.     if (dlog == (DialogPtr) nil)
  72.     {
  73.         SysBeep (1);
  74.         return;
  75.     }
  76.     SkelDialog (dlog,
  77.                 Filter,
  78.                 nil,
  79.                 nil,            /* no close box, so no close handler */
  80.                 Clobber);
  81.     ShowWindow (dlog);
  82.     SkelDoEvents (activMask + updateMask);
  83. }
  84.